﻿<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link type="text/css" rel="stylesheet" 	href="css/powerFloat.css" />
	<link type="text/css" rel="stylesheet" 	href="css/xmenu.css" />
	<link type="text/css" rel="stylesheet" 	href="css/main.css" />
	<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="js/jquery-powerFloat-min.js"></script>
	<script type="text/javascript" src="js/jquery-xmenu.js"></script>
	<script type="text/javascript" src="js/jquery-xmenu-option.js"></script>
	<link rel="stylesheet" type="text/css" href="jS/datepickup/tcal.css" />
	<link rel="stylesheet" type="text/css" href="css/xtable.css" />
    <script type="text/javascript" src="jS/datepickup/tcal.js"></script> 
    <script language="javascript" type="text/javascript" src="js/tablesort2/jquery.tablesorter.min.js"></script>
	<script type="text/javascript">
	$(document).ready(function() {
	$("#mytable").tablesorter({
		headers: {
		0:{sorter:"string"},
		1:{sorter:"string"},
		2:{sorter:"currency"},
		3:{sorter:"currency"},
		4:{sorter:"currency"},
		5:{sorter:"currency"},
		5:{sorter:"currency"},
		6:{sorter:"currency"}}
	});
	});
	</script>
	
	
<style>
.div-inline{ display:inline} 
</style>
<style> 
body{text-align:center} 
.divcss5{margin:0 auto;width:600px;height:100px;border:1px solid #000} 
</style> 



</head>
<body>
  <?php 
$username=$_GET["id"];  
$FromDate=date("m/",time())."01".date("/Y",time()); 
if(!empty($_GET['FromDate'])){ $FromDate=$_GET["FromDate"]; }
$ToDate=date("m/d/Y", strtotime("+1 months", strtotime(date("m/",time())."01".date("/Y",time()))));
if(!empty($_GET['ToDate'])){ $ToDate=$_GET["ToDate"]; } 
$selectdeptidden='ALL';
if(!empty($_GET['selectdeptidden'])){ $selectdeptidden=$_GET["selectdeptidden"]; } 

if ($selectdeptidden!='ALL') {$namequery= "select dbo.BPcontact('".str_replace(",", "','CardName')+'#'+dbo.BPcontact('", $selectdeptidden)."','CardName') CardName";}
if ($selectdeptidden!='ALL') {$CardLimitquery= "and T0.CardCode in ('".str_replace(",", "','",$selectdeptidden)."')" ;} 

$con = mysql_connect("localhost", "root", "12root34"); 
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$sql = "SELECT  `account` FROM  `dwz`.`dwz_user` WHERE  `nickname` =  '".$username."'";
$result=mysql_query($sql,$con);
$userid=mysql_fetch_row($result);
mysql_close($con);
$sqlserver='192.168.1.10'; 
$sqldatabase='GT';
$sqluser='sa2';
$sqlpassword='sasa';
$sqlconnection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$sqlserver;Database=$sqldatabase;", $sqluser, $sqlpassword);

$sqlquery="select U_BPcode,Name from dbo.[@AX_OPRATION] where U_viewer like '%".$userid[0]."%' order by U_class"; 
$result=odbc_do($sqlconnection,$sqlquery);
$maxi= odbc_num_rows($result);
$options=array(); 
while($row=odbc_fetch_row($result)){    
    $options[] = array(iconv ("gb2312","utf-8",odbc_result($result, 1)),odbc_result($result, 2));  
}

if ($selectdeptidden!='ALL') {
$result1=odbc_do($sqlconnection,$namequery);
$maxi1= odbc_num_rows($result1);
$options1=array(); 
while($row1=odbc_fetch_row($result1)){    
    $options1[] = iconv ("gb2312","utf-8",odbc_result($result1, 1));  
}
}
?>


</style> 
	<div id="main">
	  <div id="lead" >			

				<p>
<form id="form1" name="form1" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
				<br>
				<div   class="div-inline" class="topnav">
					<a id="selectdept" href="javascript:void(0);" class="as">
						<span >请选择平台          </span>
					</a>					
					
		
			
<input type="text" value="" id="selectdeptidden"  name="selectdeptidden"  style="display:none" />
<input type="text" value="<?php echo $username; ?>" id="id"  name="id"  style="display:none" />
 </div>  
 <div  class="div-inline" > 开始时间
 <input type="text" name="FromDate" class="tcal" value='<?php echo date("m/",time())."01".date("/Y",time());  $BeginDate=date('Y-m-01', strtotime(date("Y-m-d")));?>' /></div>
 <div  class="div-inline">
   结束时间
 <input type="text" name="ToDate" class="tcal" value='<?php echo date('m/d/Y', strtotime("$BeginDate +1 month -1 day")); ?>' /></div>
			
		</div>


	<!-- 弹出下拉框 -->

	  		
	 <div id="m2" class="xmenu" style="display: none;">
			<div class="select-info">	
				<label class="top-label">已选平台：</label>
				<ul>
					
				</ul>
				<a  name="menu-confirm" href="javascript:void(0);" class="a-btn">
					<span class="a-btn-text">确定</span>
				</a> 
			</div>	
			<dl>
				<dt class="open">积分业务</dt>
					<dd>       
						<ul>
				<?php
			for ($i=0; $i<$maxi; $i++) {
			echo "<li rel='".$options[$i][0]."'>";
			echo iconv("gb2312","utf-8",$options[$i][1]);
			echo "</li>";
						}
						
	?>					
						</ul>						
					</dd>
            </dl>
				 
		</div>
  <div  class="div-inline" >  <input type="submit" name="Submit" value="提交" /> </div>

</form>
	<div id="footer">
  
  <p class="validators"> </p>
   <p> </p>
   <table width="671" border="1" class="divcss5" style="WORD-WRAP: break-word"  >
     <tr>
       <th width="90" scope="col">开始时间</th>
       <th width="90" scope="col">结束时间</th>
       <th width="469" scope="col">平台</th>
     </tr>
     <tr>
       <th height="41" scope="row"><?php  echo  $FromDate;?></th>
       <td><?php  echo  $ToDate;?></td>
       <td><?php  if($selectdeptidden=='ALL') {echo  $selectdeptidden;}else{ echo $options1[0];}?></td>
     </tr>
   </table>
	</div>
 		</div>				
			</p>	
<p>
<?php


$sqlquery="select T1.u_pmanager pmanager, T2.memo U_LEADER,SUM(Quantity) SUMQTY,SUM(linetotal) SUMPRICE ,sum([linetotal]-[bankcharge]-[calclineStockprice]-[calcexpressfee]-[addexpressfee]-[giftcount]-[giftaddexpressfee]-[calctax]) PROFIT from ax_reportx T0 left join oitm T1 ON T0.Itemcode=T1.itemcode LEFT JOIN  OSLP T2 on T1.u_PMANAGER=T2.SLPNAME
where t0.docdate>='".$FromDate."' and t0.docdate<='".$ToDate."' ";
if ($selectdeptidden!='ALL') {$sqlquery=$sqlquery.$CardLimitquery;}
$sqlquery=$sqlquery." group by T1.u_pmanager, T2.memo";

 $arr=odbc_do($sqlconnection,$sqlquery); 
 
  ?>
  <div>
  <table border="1"  id="mytable" cellspacing="0" class="divcss5" ><thead> 
<tr >
 <th  style="width:16%"><div align="center">产品经理</div></th><th style="width:12%"><div align="center">产品组</div></th><th  style="width:12%"><div align="center">数量</div></th> <th  style="width:12%"><div align="center">销售金额</div></th> <th  style="width:12%" ><div align="center">销售毛利</div></th><th  style="width:12%" ><div align="center">毛利率%</div></th>
</tr>
</thead>


<tbody>
<?php
// 使用while语句循环mysql_fetch_array()函数返回的数组
while($result=odbc_fetch_array($arr)){
?>

<tr align="center">


<td><?php echo "<a href='http://192.168.1.11:8090/BrandReport/PmanagerFlowDetail.php?Pmanager=".iconv("gb2312","utf-8//IGNORE",$result['pmanager'])."&FromDate=".$FromDate."&ToDate=".$ToDate."'>".iconv("gb2312","utf-8//IGNORE",$result['pmanager'])."</a>";?></td>
<td><?php echo iconv("gb2312","utf-8//IGNORE",$result['U_LEADER']);?></td>
<td><?php echo number_format(round($result['SUMQTY'],0));?></td>
<td><?php echo number_format(round($result['SUMPRICE'],2));?></td>
<td><?php if (round($result['PROFIT'],2)<0){echo "<font color='FF6633'>".number_format(round($result['PROFIT'],2))."</font>" ;} else {echo "<font color='000099'>".number_format(round($result['PROFIT'],2))."</font>"; } ?></td>
<td><?php if (round($result['PROFIT'],2)<0){echo "<font color='FF6633'>".round($result['PROFIT']/$result['SUMPRICE']*100,2)."</font>" ;} else {echo "<font color='000099'>".round($result['PROFIT']/$result['SUMPRICE']*100,2)."</font>"; } ?></td>
</tr>

<?php 
} // 结束while循环
?>
</tbody>
</table>
</div>
</p>			
<p>
<?php


$sqlquery="select  t2.Memo U_LEADER,SUM(Quantity) SUMQTY,SUM(linetotal) SUMPRICE ,sum([linetotal]-[bankcharge]-[calclineStockprice]-[calcexpressfee]-[addexpressfee]-[giftcount]-[giftaddexpressfee]-[calctax]) PROFIT from ax_reportx T0 left join oitm T1 ON T0.Itemcode=T1.itemcode LEFT JOIN OSLP T2 on T1.U_PMANAGER=T2.SLPNAME
where t0.docdate>='".$FromDate."' and t0.docdate<='".$ToDate."' ";
if ($selectdeptidden!='ALL') {$sqlquery=$sqlquery.$CardLimitquery;}
$sqlquery=$sqlquery." group by  t2.Memo";
 $arr=odbc_do($sqlconnection,$sqlquery); 
 
  ?>
  <div>
  <table border="1"  id="mytable1" cellspacing="0" class="divcss5" >
<thead> 
<tr >
<th style="width:12%"><div align="center">产品组</div></th><th  style="width:12%"><div align="center">数量</div></th> <th  style="width:12%"><div align="center">销售金额</div></th> <th  style="width:12%" ><div align="center">销售毛利</div></th>
</tr>
</thead>



<?php
// 使用while语句循环mysql_fetch_array()函数返回的数组
while($result=odbc_fetch_array($arr)){
?>

<tr align="center">
<td><?php echo iconv("gb2312","utf-8//IGNORE",$result['U_LEADER']);?></td>
<td><?php echo round($result['SUMQTY'],0);?></td>
<td><?php echo round($result['SUMPRICE'],2);?></td>
<td><?php if (round($result['PROFIT'],2)<0){echo "<font color='FF6633'>".round($result['PROFIT'],2)."</font>" ;} else {echo "<font color='000099'>".round($result['PROFIT'],2)."</font>"; } ?></td>
</tr>

<?php 
} // 结束while循环
?>
</table>

</p>
</body>
</html>
